@tool
class_name PercentagePosAndSizeContainer
extends Container

## 该控件位置计算会始终占据父控件的百分比位置和大小

@export_group("位置")
@export var percentage_pos:Vector2:
	set(value):
		percentage_pos = value
		_on_parent_size_changed()
@export var absolute_pos:Vector2:
	set(value):
		absolute_pos = value
		_on_parent_size_changed()
@export_group("")
@export_group("大小")
@export var percentage_size:Vector2:
	set(value):
		percentage_size = value
		_on_parent_size_changed()
@export var absolute_size:Vector2:
	set(value):
		absolute_size = value
		_on_parent_size_changed()
@export_group("")
var connect_obj:ConnectObj

func _on_parent_size_changed():
	var parent_pos = (get_parent() as Control).global_position
	var parent_size = (get_parent() as Control).size
	
	position = parent_size * percentage_pos + absolute_pos
	size = parent_size * percentage_size + absolute_size

func _enter_tree() -> void:
	connect_obj = ConnectObj.new(get_parent().resized,[_on_parent_size_changed])
func _ready() -> void:
	_on_parent_size_changed()
func _notification(what: int) -> void:
	if what == NOTIFICATION_PREDELETE:
		if connect_obj:
			connect_obj.disconnect_all()
